package org.hyl.javabase.集合扩展;

import java.util.AbstractCollection;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.RandomAccess;

public class demo {
	public static void main(String[] arg) {
		//fun1();
		fun2_0();
		// fun3();
	}

	public static void fun0() {
		List1 al = new ArrList();
		al.add(98);
		al.add(23);
		al.add(23);

	}

	// 数组是如何拷贝的
	public static void fun0_1(List<String> strList) {
		int arr[] = new int[10];
		for (int i = 0; i < 10; i++) {
			int x = (int) (Math.random() * 100 + 1);
			arr[i] = x;
		}
		int arrb[] = new int[11];
		System.arraycopy(arr, 0, arrb, 0, 8);
		fun1_3(arr);
		fun1_3(arrb);
	}

	public static void fun0_2(Collection<?> c) {

	}

	public static void fun1() {
		// List<String> strList = new ArrayList<>();
		// List strList = new ArrayList();
		List<Object> strList = new ArrayList<>();
		// 1）只要是 new xxx 对象的父类或者接口，就可以用来 声明变量名
		// 2)声明类型必须 含有 我们所需要的方法
		for (int i = 0; i < 10; i++)
			strList.add("student" + i);
		fun1_0(strList);
		System.out.println();
		strList.remove(0);
		fun1_0(strList);
		System.out.println();
		strList.remove(0);
		fun1_0(strList);

		// 值传递与引用传递的区别
		// System.out.println(strList.get(3));
		// fun2_0(strList);
		// System.out.println(strList.get(3));
		//
		// int i=10;
		// System.out.println(i);
		// fun2_0_1(i);
		// System.out.println(i);
	}

	public static void fun2_0() {
		sqlList strList = new sqlList("demo");
		System.out.println(strList);

		strList.insert("xiaohong");
		strList.insert("xiaoming");
		System.out.println("selectall");
		strList.selectall();		
		fun1_0((List<?>)strList.get());
		fun1_0_1((List<?>)strList.get());
	}
	public static void fun2_1() {
		sql strList = new sqlSet("demo");
		strList.insert("xiaohong");
		strList.insert("xiaoming");
		System.out.println("selectall");
		strList.selectall();		
		fun1_0((List<?>)strList.get());
		fun1_0_1((List<?>)strList.get());
	}
	// 变量集合的两种方式
	public static void fun1_0(List<?> strList) {
		// 使用for-each循环
		System.out.println("fun1_0");
		for (Object obj : strList) {
			System.out.println(obj.toString() + " ");
		}
	}

	public static void fun1_0_1(List<?> strList) {
		// using iterator
		System.out.println("fun1_0_1");
		Iterator<?> it = strList.iterator();
		while (it.hasNext()) {
			Object obj = it.next();
			System.out.println(obj.toString());
		}
	}

	public static void fun1_3(int[] a) {
		// 使用for-each循环
		for (int i : a) {
			System.out.print(i + " ");
		}
		System.out.println();
	}

	public static void fun7_0() {
	
	}

	public static void fun3_0() {

		HashMap<String, Integer> hm = new HashMap<String, Integer>();
		hm.put("zdy", 13);
		hm.put("xml", 14);
		hm.put("zk", 19);

		System.out.println(hm.get("xml"));
	}
}
